package com.ms.service.module.analysis;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public enum PlatformType {
	//這邊要跟C端同步登入平台
	
	WINDOWS_PC,
	
	IOS_APPSTORE,
	
	IOS_OFFICAL,
	
	ANDROID_GOOGLEPLAY,
	
	ANDROID_OFFICAL,
	
	H5_MOBILE,
	
	H5_WINDOWS;
	
	/** log object */
	private static final Log log = LogFactory.getLog(PlatformType.class);
	
	public static PlatformType getENUMbyString(String platformString){		
		try{
			//C送過來的平台名稱長這樣"WindowsPlayer; WINDOWS-PC"
			String platforms[] = platformString.split(";");
			//我們只需要後面的，但是DB裡面是用ENUM存，ENUM不能用"-"，所以在這邊轉換成"_"
			String platformFinal = platforms[1].trim().replace("-", "_");
			PlatformType platformType = PlatformType.valueOf(platformFinal);
			return platformType;
		}
		catch(Exception e){
			if(log.isErrorEnabled()){
				log.error("Illegal Platform: " + platformString, e);
			}
			return null;
		}
	}	
}
